<template>
    <div>
      <app-head :title="title"></app-head>
      <div class="content">
            <h1 class="title">新媒体运营必备：追热点原来这么简单！</h1>

        <div class="text">
          <textarea name="" v-model="text" id="" cols="30" rows="10" placeholder="留言将由管理员审核后显示"></textarea>
        </div>
      <div>
        <button class="btn_d act" @click="push">提交</button>
      </div>

        <!--留言板-->

      </div>
      <div class="word">

        <div class="que_c ">
          <div class="que" v-for="(item,index) in messages">
            <dl class="img_d"><img :src="item.headImg" alt=""></dl>
            <dl style="margin-left: 12px;text-align: left">

              <dt class="name">{{item.datetime}}</dt>
              <dt class="con">{{item.content}}</dt>
              <dt class="data">{{item.outTime}}  <span @click="del(item.id,index)" style="color: #0076FF;font-size: 12px;margin-left: 10px">删除</span></dt>
              <div class="res" v-if="leaveWordMangeLen">
                <dl>管理员回复</dl>
                <p>{{item.leaveWordMange[0].content}}</p>
                <span>{{item.leaveWordMange[0].outTime}}</span>
              </div>
            </dl>
            <div class="line" v-if="index!=5"></div>

          </div>

        </div>
      </div>

      <!--弹窗-->
      <div class="mask" v-if="is_mask">
         <div class="mask_con">
            <p class="title">确定删除此留言吗?</p>
            <div class="active">
              <span @click="ok">确定</span>
              <span @click="cancel">取消</span>
            </div>
         </div>
      </div>
    </div>
</template>

<script>
  import AppHead from '@/components/Head'
    export default {
        name: "Comment",

        components:{
          AppHead
        },
        data () {
          return {
            title: '留言',
            messages:[],
            leaveWordMangeLen:true,
            is_mask:false,
            mes_id:'',
            mes_ind:'',
            text:''
          }
        },
        mounted:function () {
          this.init()
        },
      methods:{
          init:function () {
            var that = this
            this.$http({
              method: 'get',
              url: '/article/leaveWordUser',
              // params:{
              //   id:that.$route.query.id
              // }
            }).then(function (res) {

              that.messages = res.data.datas
              if(!that.messages[0].leaveWordMange[0].content){
                that.leaveWordMangeLen = false
              }else{

              }

            }).catch(function (error) {

            })
          },
        del:function (id,ind) {
            var that = this
          that.mes_id = id
          that.mes_ind = ind

          that.is_mask = true

        },
        cancel:function () {
          this.is_mask = false
        },
        ok:function () {
          this.$delete(this.messages,this.mes_ind)
          this.is_mask = false


        },
        //发布留言
        push:function () {
            console.log(this.text)
          var that =this
          var params= new FormData()
          params.append("content",this.text)
          params.append("id",this.$route.query.id)

          //模拟数据发布之后的效果，正式上线需要注释  139-147行

          that.$layer.alert("提交成功!",{
            shade:true,
            btn: '',
            shadeClose: true,//点击遮罩是否关闭

          });
          setTimeout(function () {
            window.location.reload()
          },1500)

          //  真实发布留言之后调用的接口
          that.$http({
            method: 'post',
            url: '/comment/pushComment',
            data:params
          }).then(function (res) {
              if(res.status==200){
                that.$layer.alert("提交成功!",{
                  shade:true,
                  btn: '确定',
                  shadeClose: true,//点击遮罩是否关闭

                });
                setTimeout(function () {
                  window.location.reload()
                },1500)
              }
          }).catch(function (error) {

          })
        }
      }
    }
</script>

<style scoped lang="less">

  .content{
    padding: 12px 24px;
    padding-bottom: 24px;
    background: #fff;
    margin-top: 4px;
  }
  .title{
    color: #333;font-size: 22px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: box;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    height: initial;
    -webkit-box-orient: vertical;
    white-space: initial;font-weight:400;text-align: left;line-height:30px;
  }
  .flex_b{
    justify-content: space-between;
  }
  .flex_b p{
    font-size:13px;
    color: #999;
    margin: 0;
  }
  .text{

    font-size:16px;
    line-height:27px;
    text-align: left;color: #333333;
    margin-top: 16px;
    textarea{
      border:1px solid #eee;
      width: 90%;
      outline: none;
      padding: 12px 16px;
      padding-left: 16px!important;
      color: #CCCCCC;
      font-size: 15px;
      height: 150px;
    }
  }
  .atta{
    border:1px solid #eee;
    padding: 8px 16px;
    text-align: left;
    margin: 16px 0;
  }
  .record{
    text-align: left;
  }
  .record span{
    font-size: 13px;
    color: #999999;
  }
  .word{
    margin-top: 32px;
    padding: 0 16px;
    background: #f4f4f4;
    font-size: 15px;
    color: #999;

  }
  .more{
    height:21px;
    font-size:15px;
    color: #ccc;
    text-align: center;
    padding: 16px 0;
  }
  .que{
    display:-webkit-box;
    display:-ms-flexbox;
    display:-webkit-flex;
    display:flex;
    position: relative;
    .img_d{
      width: 34px;
      height: 34px;
      img{
        width: 100%;
        height: 100%;
      }
    }
    .name{
      font-size: 15px;
      color: #666;
    }
    .con{
    color: #444444;
      font-size:16px;
      line-height: 22px;
      margin: 4px 0;
    }
    .data{
      font-size: 12px;
      color: #999;
    }
  }
  .line{
    height:1px;
    width: 327px;
    background:rgba(238,238,238,1);
    position: absolute;
    bottom: 0;
  }
  .que_c{

  }
  .res{
    dl{
      margin: 8px 0;
      border-left: 2px solid #5CB31B;
     padding-left: 4px;font-size: 15px;color: #666;
    }
    p{
      font-size: 16px;
      color: #444444;
      margin-bottom: 4px;
    }
    span{
      color: #999999;font-size: 12px;
    }
  }
  .btn_d{

    height:44px;
    line-height: 44px;
    color: #fff;
    font-size: 17px;
    background:#CCCCCC;
    border-radius:8px;
    border:1px solid #D8E5F4;
    display: inline-block;
    outline: none;

    margin-top: 10px;
    width: 100%;
  }
  .btn_d.act{
    background: #4A90E2;
    color: #fff;
  }
  .mask{

    position: fixed;
    top:0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,.2);
    .mask_con{
      background: #fff;
      width: 70%;
      /*height: 100px;*/
      margin: 0 auto;
      margin-top: 60%;
      border-radius: 12px;
      .title{
        height: 65px;
        line-height: 65px;
        font-size: 17px;
        text-align: center;
        border-bottom: 1px solid #eee;
      }
      .active{
        font-size: 17px;
        text-align: center;
        height: 48px;
        line-height: 48px;
        span{
          width: 40%;
          display: inline-block;
          vertical-align: middle;
        }
      }
    }
  }
</style>
<style lang="less">
  html{
    .vl-notify.vl-notify-alert h2.vl-notice-title{
      display: none!important;
    }
    .vl-notify .vl-notify-btns{
      padding: 0;
    }
    .vl-notify.vl-notify-main{
      box-shadow:none;
    }
    .vl-notify .vl-notify-content{
      font-size: 15px;
      color: #333333;
      text-align: center;line-height:46px;
    }
    .vl-notify-mask{
      background: rgba(0,0,0,.5);
    }
    .vl-notify-btns{
      width: 100%;
      display: none;
      height: 48px;
      line-height: 48px;
      border: 1px solid rgba(238,238,238,1);;
      .notify-btn-primary{
        height: 48px;
        display: none;
        background: #fff;
        text-align: center;color: #0076FF;
        border: none;
        width: 100%;
        margin: 0 auto;font-size:17px;
      }
    }

  }
</style>
